package com.jt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;


@Component  /*交给spring容器管理*/
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        /*获取当前时间
        * metaObject对象 是mp自动填充的对象
        * */
        Date date=new Date(); /*事件对象类*/
        this.setFieldValByName("created",date , metaObject);
        this.setFieldValByName("updated",date , metaObject);
    }


    @Override
    public void updateFill(MetaObject metaObject) {
        Date date = new Date(); /*事件对象类*/
        this.setFieldValByName("created", date, metaObject);
    }
}
